package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.getIndependentAgentPicBean;
import com.ymatou.iapi.godmch.parameter.registerByCodeBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymatou.iapi.godmch.service.getIndependentAgentPicCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
/**
*获取邀请分销代理分享图片(独立云)
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getIndependentAgentPic{
	private static getIndependentAgentPicBean bean;
	private static getIndependentAgentPicCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取邀请分销代理分享图片(独立云)");
	}

	@Before
	public void caseUp() {
		bean=new getIndependentAgentPicBean();
		call=new getIndependentAgentPicCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getIndependentAgentPic_001() {
		Logger.start(true,"获取邀请分销代理分享图片(独立云)-验证商户是独立商户的分销小店代理");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createBean.setMchShareType(3);// 店铺买家端呈现形式//1：小程序 2：H5 3：独立小程序 4：独立h5 5：继承版小程序
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Integer mchId=createCall.getmchId();
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);//
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", createCall.getmchId());
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createCodeCall.getCode());
			GodmchManageCallService.registerByCodeCall(registerByCodeBean);
			
			bean.setMchId(mchId);
			bean.setInviteCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			Logger.verifyEquals(true, call.getPicUrl().length()>0, "验证PicUrl");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getIndependentAgentPic_002() {
		Logger.start(true,"获取邀请分销代理分享图片(独立云)-验证商户是独立商户的不是分销小店代理");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Integer mchId=createCall.getmchId();
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
//			// 创建代理类型
//			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
//			createagentBean.setAgentMode(2);//
//			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", createCall.getmchId());
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
		//	createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			createCodeBean.setRoleType(agenttypeList.get(1).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createCodeCall.getCode());
			GodmchManageCallService.registerByCodeCall(registerByCodeBean);
			
			bean.setMchId(mchId);
			bean.setInviteCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			Logger.verifyEquals(true, call.getPicUrl().length()>0, "验证PicUrl");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getIndependentAgentPic_003() {
		Logger.start(true,"获取邀请分销代理分享图片(独立云)-验证商户Id不存在");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Integer mchId=createCall.getmchId();
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);//
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", createCall.getmchId());
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createCodeCall.getCode());
			GodmchManageCallService.registerByCodeCall(registerByCodeBean);
			
			bean.setMchId(999999);
			bean.setInviteCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getIndependentAgentPic_004() {
		Logger.start(true,"获取邀请分销代理分享图片(独立云)-验证商户Id为空");
		try {
			
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Integer mchId=createCall.getmchId();
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);//
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", createCall.getmchId());
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, createCodeCall.getCode());
			GodmchManageCallService.registerByCodeCall(registerByCodeBean);
			
			//bean.setMchId(999999);
			bean.setInviteCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}